function hideComment(target){
	$target = $(target);
	$target.parent().addClass("hidden");
}
function showComment(boxid,replyTo){ 
	$("#"+boxid).removeClass("hidden").children("textarea").focus();
	if(replyTo){
		$("#"+boxid).children("textarea").val("@"+replyTo+" ");
	}else{
		$("#"+boxid).children("textarea").val("");
	}
}
function showReplyLink(target){ 
	$(target).children("a").removeClass("hidden");
}
function hideReplyLink(target){ 
	$(target).children("a").addClass("hidden");
}

function categoryClicked(target){ 
	if($(target).hasClass("active")) return;
	$ul = $(target).parent();
	$(".active",$ul).removeClass("active");
	$(target).addClass("active");
}
function taggingKeydown(event,target){  
	if(event.keyCode==8){  
		var text = $(target).val();
		if(text == ""){
			var $tag = $(target).parent().children("ul").children("li:last-child");
			$tag.remove();
		}
	}
	if(event.keyCode==13){ 
		var text = $(target).val();
		if(text != ""){ 
			addTag(text);
			$(target).val("");
		} 
	}
}
function taggingAdd(target){
	var text = $(target).text();
	addTag(text);
}
function addTag(tagName){
	var item = '<li title="'+tagName+'"><a class="tag">'+tagName+'<span class="close" onclick="taggingRemove(this);">×</span></a></li>';
	$("ul#tags").append(item);
}
function taggingRecClose(target){
	$(target).parent().addClass("hidden");
}
function taggingRecOpen(){
	$("#tag-rec").removeClass("hidden");
}
function taggingRemove(target){
	$(target).parent().parent().remove();
}

function post(){
	var title = $("#title").val(); 
	var category = $("#category .active").val(); 
	var content = editor.getContent(); 
	var tags = "";
	var tagSet = {}
	$("#tags li").each(function(index){ 
		var tagName = $(this).attr("title");
		tagSet[tagName] = 1; 
	});   
	for(var tag in tagSet){
		tags += tag + " ";
	}
	$.post('/forum/post',
			{
				'title':title,
				'category': category,
				'content': content,
				'tags': tags
			}, 
			function(data){
				if(data.success){
					window.location = "/forum/thread/"+data.id;
				}
			}
	);
}